/**
 * KopsoxApplicationServices
 * Copyright (C) 2010 Free Software Foundation, Inc. <http://fsf.org/>
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.kopsox.services.application;

import java.io.Serializable;
import java.security.Principal;

import org.kopsox.services.security.PrincipalGroup;
import org.kopsox.services.security.Role;

/**
 * The SessionContext represents the context of an user session and is therefore unique for an user
 * 
 * @author Konrad Renner
 *
 */
public interface Session extends Serializable {

	/**
	 * Gets the Principal (user) of the current session
	 * 
	 * @return Principal
	 * @author Konrad Renner
	 */
	public Principal getPrincipal();
	
	/**
	 * Checks if the Principal has the given role.<br>
	 * 
	 * @param role
	 * @return boolean
	 * @author Konrad Renner
	 */
	public boolean isUserInRole(Role role);
	
	/**
	 * Checks if the Principal is in the given group.<br>
	 * 
	 * @param group
	 * @return boolean
	 * @author Konrad Renner
	 */
	public boolean isUserInGroup(PrincipalGroup group);
	
	/**
	 * Sets an attribute into the session
	 * 
	 * @param name
	 * @param attribute
	 * @author Konrad Renner
	 */
	public void setAttribute(String name, Object attribute);
	
	/**
	 * Sets an attribute by its name
	 * 
	 * @param name
	 * @return Object
	 * @author Konrad Renner
	 */
	public Object getAttribute(String name);
	
	/**
	 * Checks if the Session is alive (valid)
	 * 
	 * @return boolean
	 * @author Konrad Renner
	 */
	public boolean isSessionAlive();
	
	/**
	 * Reactivates the Session
	 * 
	 * @return boolean
	 * @author Konrad Renner
	 */
	public boolean reactivateSession();
	
	/**
	 * Passivates the Session
	 * 
	 * @return boolean
	 * @author Konrad Renner
	 */
	public boolean passivateSession();
	
}
